package com.shambles.weixin.controller;

import com.github.pagehelper.PageInfo;
import com.shambles.manage.model.entity.RestResponse;
import com.shambles.manage2.service.SubscribeService;
import com.shambles.manage2.tkmapper.entity.MessageRequestVM;
import com.shambles.manage2.tkmapper.entity.SubscribeInformation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 预约信息查询接口
 */
@RestController
@RequestMapping("subscribe")
public class SubscribeController {
    @Autowired
    private SubscribeService subscribeService;

    /**
     * 查询预约明细类型和数量
     */
    @PostMapping("subscribeInformation")
    @ResponseBody
    public SubscribeInformation querySubscribeInfo(String id) {
        return this.subscribeService.querySubscribeInfo(id);
    }

    /**
     * 个人预约信息记录
     */
    @PostMapping("subscribePersonalInfo")
    @ResponseBody
    public RestResponse queryPersonalInfo(HttpServletRequest request,Integer pageIndex,Integer pageSize){
        //预约人的openID
        String openId = (String) request.getSession().getAttribute("openId");
        MessageRequestVM messageRequestVM = new MessageRequestVM();
        messageRequestVM.setPageIndex(pageIndex);
        messageRequestVM.setPageSize(pageSize);
        PageInfo<SubscribeInformation> pageInfo =  subscribeService.queryPersonalInfo(messageRequestVM,openId);
        return RestResponse.ok(pageInfo);
    }
}
